/*
* Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
*/
package com.laihuichuxing.pool.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.laihuichuxing.common.config.CacheConfig;
import com.laihuichuxing.pool.DriverRpPool;
import com.laihuichuxing.pool.entity.DriverEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @author: Qinxuefeng
 * @since: 1.0
 * Create Date Time: 2018/10/10 11:21
 * Update Date Time:
 */
@Component
public class DriverRpPoolImpl implements DriverRpPool {
    @Autowired
    StringRedisTemplate redisTemplate;
    @Override
    public void offer(DriverEntity driverEntity){
        redisTemplate.opsForValue().set(CacheConfig.DRIVERRP+driverEntity.getDriverMobile(),driverEntity.toString());

    }
    @Override
    public DriverEntity take(DriverEntity driverEntity) {
        DriverEntity driver = new DriverEntity();
        String str=redisTemplate.opsForValue().get(CacheConfig.DRIVERRP+driverEntity.getDriverMobile());
        if(!Strings.isNullOrEmpty(str)){
            Map<String,String> map = Splitter.on(",").withKeyValueSeparator("=").split(str);
            driver = JSON.parseObject(JSON.toJSONString(map), DriverEntity.class);
        }
        return driver;
    }

}
